Bee.Window = Ext.extend(Ext.Window, {
    buttonAlign: 'center',
    layout: 'fit',
    minWidth: 370,
    width: 370,
    height: 300,
    closeAction: 'hide',
    //plain: true,
    modal: true,
    getForm: function(){
        return this.form;
    },
    getBasicForm: function(){
        return this.basicForm;
    },
    onRender: function(ct, position){
        Bee.Window.superclass.onRender.call(this, ct, position);
        
        if (this.items && this.items.get(0) && this.items.get(0) instanceof Bee.form.DWRForm) {
            this.form = this.items.get(0);
            this.basicForm = this.form.form;
        }
    },
    // private    
    afterShow: function(isAnim){
        this.proxy.hide();
        this.el.setStyle('display', 'block');
        this.el.show();
        if (this.maximized) {
            this.fitContainer();
        }
        // work around stupid FF 2.0/Mac scroll bar bug
        if (Ext.isMac && Ext.isGecko) {
            this.cascade(this.setAutoScroll);
        }
        if (this.monitorResize || this.modal || this.constrain || this.constrainHeader) {
            Ext.EventManager.onWindowResize(this.onWindowResize, this);
        }
        this.doConstrain();
        this.doLayout();
        if (this.keyMap) {
            this.keyMap.enable();
        }
        this.toFront();
        this.updateHandles();
        if (isAnim && (Ext.isIE || Ext.isWebKit)) {
            var sz = this.getSize();
            this.onResize(sz.width, sz.height);
        }
        if (this.basicForm) {
            this.basicForm.reset();
            this.basicForm.isValid();
            this.action = 'save';
        }
        this.fireEvent('show', this);
    },
    load: function(params, animateTarget, cb, scope){
        Bee.Window.superclass.show.call(this, animateTarget, cb, scope);
        if (this.form) {
            this.form.load(params);
            this.action = 'update';
        }
    },
    maximize: function(){
        if (!this.maximized) {
            this.expand(false);
            this.restoreSize = this.getSize();
            this.restorePos = this.getPosition(true);
            if (this.maximizable) {
                this.tools.maximize.hide();
                this.tools.restore.show();
            }
            this.maximized = true;
            this.el.disableShadow();
            if (this.dd) {
                this.dd.lock();
            }
            if (this.collapsible) {
                this.tools.toggle.hide();
            }
            this.el.addClass('x-window-maximized');
            this.container.addClass('x-window-maximized-ct');
            this.setPosition(0, 0);
            this.fitContainer();
            this.fireEvent('maximize', this);
        }
        return this;
    },
    restore: function(){
        if (this.maximized) {
            this.el.removeClass('x-window-maximized');
            if (this.maximizable) {
                this.tools.restore.hide();
                this.tools.maximize.show();
            }
            this.setPosition(this.restorePos[0], this.restorePos[1]);
            this.setSize(this.restoreSize.width, this.restoreSize.height);
            delete this.restorePos;
            delete this.restoreSize;
            this.maximized = false;
            this.el.enableShadow(true);
            if (this.dd) {
                this.dd.unlock();
            }
            if (this.collapsible) {
                this.tools.toggle.show();
            }
            this.container.removeClass('x-window-maximized-ct');
            this.doConstrain();
            this.fireEvent('restore', this);
        }
        return this;
    },
    buttons: [{
        text: '确定',
        handler: function(o){
            var form = o.ownerCt.ownerCt.getBasicForm();
            if (form) {
                if (form.isValid()) {
                    Ext.Msg.confirm('提交', '确认要提交表单里的内容吗？', function(para){
                        if (para == 'yes') {
                            o.ownerCt.ownerCt.form[o.ownerCt.ownerCt.action]();
                        }
                    });
                }
                else {
                    Bee.msg('表单中的字段未通过效验，请检查后再提交！');
                }
            }
            else 
                if (o.ownerCt.ownerCt.save) {
                    o.ownerCt.ownerCt.save();
                }
        }
    }, {
        text: '取消',
        handler: function(o){
            o.ownerCt.ownerCt.hide();
        }
    }]
});
